'use strict';

define(['controllers', '../service/nodeService'], function (controllers) {
    controllers.solr.register('NodeController', ['$scope', 'NodeService', function ($scope, nodeService) {
        $scope.init = function () {
            $scope.query_host = '';
            $scope.query_solrVersion = '';
            $scope.query_available = '';
            $scope.pageNo = 1;
            $scope.pageSize = 10;
        };

        $scope.query = function () {
            nodeService.query({
                host: $scope.query_host,
                available: $scope.query_available,
                solrVersion: $scope.query_solrVersion,
                pageNo: $scope.pageNo,
                pageSize: $scope.pageSize
            }, function (data) {
                $scope.paged = data.paged;
                $scope.monitorMap = data.monitorMap;
                $scope.hostnames = data.hostnames;
                $scope.solrVersions = data.solrVersions;
            });
        };

        $scope.confirmRemove = function (collection) {
            $scope.removeId = collection.id;
            $('#removeDialog').modal('show');
        };

        $scope.remove = function () {
            nodeService.remove({id: $scope.removeId});
        };

        $scope.init();
        $scope.query();
    }]);
});